//
//  WHContactsResultTableView.m
//  AddressBook
//
//  Created by  on 2020/7/30.
//  Copyright © 2020 wh. All rights reserved.
//

#import "WHContactsResultTableView.h"

static NSString *cellId = @"resultCell";

@interface WHContactsResultTableView () <UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong) NSArray *nameArr;

@end


@implementation WHContactsResultTableView

- (instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style
{
    if (self = [super initWithFrame:frame style:style]) {
        self.delegate = self;
        self.dataSource = self;
        self.tableFooterView = [[UIView alloc] init];
    }
    return self;
}

- (void)setContentWithArr:(NSArray<NSString *> *)contentArr
{
    self.nameArr = contentArr;
}
#pragma mark - tableView delegate
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
    
    if (!cell) {
        cell = [[ UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
    }
    cell.textLabel.text = self.nameArr[indexPath.row];
    return cell;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
        return self.nameArr.count;

}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 60;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (self.resultDelegate && [self.resultDelegate respondsToSelector:@selector(resultCellAction:)]) {
        [self.resultDelegate resultCellAction:self.nameArr[indexPath.row]];
    }
}
//tableView滑动时 退出编辑模式
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
    [self.superview endEditing:YES];
}
#pragma mark - 懒加载
- (NSArray *)nameArr
{
    
    if (!_nameArr) {
        _nameArr = [[NSArray alloc] init];
    }
    return _nameArr;
}
@end
